//封装柱状图
import * as echarts from 'echarts';
import { useEffect,useRef } from 'react';

//1.功能代码放入组件中
//2.将可变的部分抽象成prop参数


const BarChart = ({title})=>{
    const chartRef =  useRef(null)
    useEffect(() => {
        //保证dom可用，进行图标渲染
        var chartDom = chartRef.current;
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            title:{
                text:title
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['Vue',"React","Angular"],
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: 'Direct',
                    type: 'bar',
                    data: [10,40,70]
                }
            ]
        };

        option && myChart.setOption(option);
    }, [])

  return  <div  ref={chartRef} style={{
        width: 300,
        height: 300
    }}>home</div>
}
export default BarChart
